<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>     
    let loginList = [ 
  {userName: 'admin', password: 'admin321'},
  {userName: 'zhangsan', password: 'zs321'},
  {userName: 'lisi', password: 'ls321'},
  {userName: 'yyqx', password: 'yyqx321'}
]
// 现有的用户信息列表
// 根据生成的token 去掉找到 对应的信息
let userInfo = {
  token1: {
    city: '杭州',
    money: '1000w',
    sex: '女',
    userName: 'admin',
    password: 'admin321'
  },
  token2: {
    city: '南京',
    money: '1100w',
    sex: '女',
    userName: 'zhangsan',
    password: 'zs321'
  },
  token3: {
    city: '北京',
    money: '800w',
    sex: '男',
    userName: 'lisi', 
    password: 'ls321'
  },
  token4: {
    city: '天津',
    money: '600w',
    sex: '男',
    userName: 'yyqx',
    password: 'yyqx321'
  }
}   
let count1=0
let count2=0
  while(true){ 
        let userName=prompt('请输入用户名')
        let password=prompt('请输入密码')        
      // loginList.forEach(function(item,index,array){
      //  if(userName===item.userName&&password===item.password){
      //   ran=Math.floor(Math.random()*(4-1+1))+1
      //           alert(`登录成功,具体用户信息如下:
      //           city:${userInfo['token'+ran].city}
      //           money:${userInfo['token'+ran].money}
      //           sex:${userInfo['token'+ran].sex}
      //           userName:${userName}`) 
              
      //  }
      //   })
    for(let i=0;i<loginList.length;i++){
            if(userName===loginList[i].userName && password===loginList[i].password){
            
                ran=Math.floor(Math.random()*(4-1+1))+1
                alert(`登录成功,具体用户信息如下:

                city:${userInfo['token'+ran].city}
                money:${userInfo['token'+ran].money}
                sex:${userInfo['token'+ran].sex}
                userName:${userName}`) 
                console.log(i); 
                break
            }
            count1++
      } 
      // document.write(count1);
      if(count1===loginList.length){
             let num=Number(prompt('账户不存在1.注册 2.直接退出'))
             
           if(num === 1){
              let u=prompt('请输入要注册的用户名')
              let p=prompt('请输入要注册的密码')
              let obj={}
              obj.userName=u
              obj.password=p
              loginList.push(obj)
              alert('注册成功,直接去登录')

              // document.write(loginList.length);
              // console.log(loginList);

              let userName=prompt('请输入用户名')
              let password=prompt('请输入密码')  
             
            for(let i=0;i<loginList.length;i++){
            if(userName===loginList[i].userName && password===loginList[i].password){
               
              ran=Math.floor(Math.random()*(4-1+1))+1
                alert(`登录成功,具体用户信息如下:

                city:${userInfo['token'+ran].city}
                money:${userInfo['token'+ran].money}
                sex:${userInfo['token'+ran].sex}
                userName:${userName}`) 
                // console.log(i); 
                break
            } 
            count2++          
        }
        // document.write(count2); 
        if(count2===loginList.length){
          alert('再次输错，无机会，直接退出')
        }

         }else if(num===2){
                alert('退出退出退出')
                break
            }
            break
          }
      break           
        }
    </script>
</body>
</html>